package com.hzqy.web.ac.industry;

import com.alibaba.fastjson.JSONObject;
import com.hzqy.commons.conf.SystemConfig;
import com.hzqy.commons.utils.HttpUtil;
import com.hzqy.commons.utils.SystemConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/industry/itf")
public class CirculationCodeAction {
    protected final Logger LOG = LoggerFactory.getLogger(getClass());

    @ResponseBody
    @RequestMapping("/startSrsPushByContent")
    public Object startSrsPushByContent(HttpServletRequest request,String playUrls,String mode,String playModes){
        Map<String, String> map = new HashMap<String, String>();
        String itfUrl = SystemConfigUtils.getSysConfig("startSrsFlow");
        String url = itfUrl+"?playUrls="+playUrls+"&mode="+mode+"&playModes="+playModes;
        LOG.debug("发起startSrsPushByContent请求："+url);
        map = HttpUtil.get(url);
        if("1".equals(map.get("success"))){//成功
            JSONObject json = JSONObject.parseObject(map.get("msg"));
            LOG.debug("返回startSrsPushByContent请求结果："+json);
            return json;
        }else{
            LOG.debug("返回startSrsPushByContent请求结果："+map);
            return map;
        }
    }

    @ResponseBody
    @RequestMapping("/queryStatusByContentId")
    public Object queryStatusByContentId(HttpServletRequest request,String contentId){
        Map<String, String> map = new HashMap<String, String>();
        String itfUrl = SystemConfigUtils.getSysConfig("selectSrsFlowStatus");
        String url = itfUrl+"?contentId="+contentId;
        LOG.debug("发起queryStatusByContentId请求："+url);
        map = HttpUtil.get(url);
        if("1".equals(map.get("success"))){//成功
            JSONObject json = JSONObject.parseObject(map.get("msg"));
            LOG.debug("返回queryStatusByContentId请求结果："+json);
            return json;
        }else{
            LOG.debug("返回queryStatusByContentId请求结果："+map);
            return map;
        }
    }

    @ResponseBody
    @RequestMapping("/kickSrs")
    public Object kickSrs(HttpServletRequest request,String app,String name){
        Map<String, String> map = new HashMap<String, String>();
        String itfUrl = SystemConfigUtils.getSysConfig("deleteSrsFlow");
        String url = itfUrl+"?app="+app+"&name="+name;
        LOG.debug("发起kickSrs请求："+url);
        map = HttpUtil.get(url);
        if("1".equals(map.get("success"))){//成功
            JSONObject json = JSONObject.parseObject(map.get("msg"));
            LOG.debug("返回kickSrs请求结果："+json);
            return json;
        }else{
            LOG.debug("返回kickSrs请求结果："+map);
            return map;
        }
    }
}
